package org.base.mode.controller;

import org.base.mode.entity.Test;
import org.base.mode.service.TestService;
import org.base.mode.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * CRC
 * 2022/2/5
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestService testService;


    /**
     * 获取数据列表
     *
     * @param test
     * @return
     */
    @GetMapping("/list")
    public R getTestList(Test test) {
        List<Test> list = testService.getTestList(test);
        return R.success(list);
    }


    /**
     * 保存数据
     *
     * @param test
     */
    @PostMapping("/save")
    public R saveTest(@RequestBody Test test) {
        testService.saveTest(test);
        return R.success();
    }


    /**
     * 更新数据
     *
     * @param test
     * @return
     */
    @PutMapping("/update")
    public R updateTest(@RequestBody Test test) {
        testService.updateTest(test);
        return R.success("更新成功");
    }

    /**
     * 删除数据
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public R deleteTest(@PathVariable int id) {
        testService.deleteTestById(id);
        return R.success("删除成功");
    }


}
